<!doctype html>
<html>

	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="css/mui.css" rel="stylesheet" />
		<link href="css/change_user_info.css" rel="stylesheet" />
	</head>

	<body>
		<script src="js/mui.js"></script>
		<script type="text/javascript">
			mui.init()
		</script>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">修改信息</h1>
		</header>
		<div class="mui-content">
			<div class="content">
				<input id="text" type="text" name=""  value="" />
				<input id="commit" type="button" name="" value="修改" />
			</div>
		</div>
		
		<script type="text/javascript">
			mui.plusReady(function () {
			    var self = plus.webview.currentWebview();
			    var val = self.val;//获得参数
				var load = self.load;
				var can = self.can;
				document.getElementById('text').value = val;
				
				// 重构back函数
				var old_back = mui.back;
				mui.back = function() {
				    // 获取目标口窗口对象
				    var target = plus.webview.getWebviewById('setting.html');
				    // var target = plus.webview.getWebviewById("my/my.html");
				    // 执行相应的事件
				    mui.fire(target, 'customEvent', {});
				    // 执行关闭
				    old_back();
				};
				
				
			});
			document.getElementById('commit').addEventListener('tap',function(){
				this.setAttribute('disabled','false');
				this.value = '修改中';
				var new_info = document.getElementById('text').value
				var self = plus.webview.currentWebview();
				var val = self.val;//获得参数
				if(val == new_info){
					mui.toast('小主没做任何修改哦')
					this.removeAttribute('disabled');
					this.value = '修改';
					return
				}
				var load = self.load;
				var can = self.can;
				// mui.alert(localStorage.getItem('request_url')+ "cost/user/"+ load + "/?token="+localStorage.getItem('uid'))
				mui.ajax(localStorage.getItem('request_url')+ "cost/user/"+ load + "/?token="+localStorage.getItem('uid'), {
				    data:"token=" + localStorage.getItem('uid') +'&'+ can +'=' + new_info,
				    dataType:'json',  
				    type:'POST',  
				    contentType:"application/x-www-form-urlencoded; charset=utf-8",  
				    timeout:2000,  
				    success:function show(e){
						if(can == 'username'){
							localStorage.setItem('login_name', e.data.username);
						}else{
							localStorage.setItem('login_tel', e.data.tel);
						}
						mui.toast('更新成功...',{duration: 1500,});
						mui.back()
					},  
				    error:function(xhr,type,errorThrown){
						// mui.alert(xhr.responseText)
						var data = JSON.parse(xhr.responseText)
						if (data.code==0){
							mui.toast('修改失败,您输入信息不符合我们的约定哦',{ duration:'long',})
						}else{
							mui.toast(data.msg)
							mui.toast(data.data.rule,{ duration:'long'})
						}
				    }  
				});
				this.removeAttribute('disabled');
				this.value = '修改';
			})
		</script>
	</body>

</html>
